using System.Collections;
using System.Collections.Generic;

namespace PS.WebParts.Rollup.Core
{
    public class FieldInfoCollection : ICollection<FieldInfo>
    {
        private List<FieldInfo> fields = new List<FieldInfo>(16);

        public FieldInfo this [string internalName]
        {
            get
            {
                foreach (FieldInfo info in fields)
                {
                    if (info.InternalName == internalName)
                        return info;
                }
                return null;
            }
        }

        public void Add(FieldInfo field)
        {
            fields.Add(field);
        }

        public void Clear()
        {
            fields.Clear();
        }

        public bool Contains(string internalName)
        {
            return this[internalName] != null;
        }

        public bool Contains(FieldInfo item)
        {
            return  fields.Contains(item);
        }

        public void CopyTo(FieldInfo[] array, int arrayIndex)
        {
            fields.CopyTo(array, arrayIndex);
        }

        public bool Remove(FieldInfo item)
        {
            return fields.Remove(item);
        }

        public int Count
        {
            get { return fields.Count; }
        }

        #region ICollection<FieldInfo> Members

        public bool IsReadOnly
        {
            get { return false; }
        }

        #endregion

        #region IEnumerable<FieldInfo> Members

        IEnumerator<FieldInfo> IEnumerable<FieldInfo>.GetEnumerator()
        {
            return fields.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            return fields.GetEnumerator();
        }

        #endregion
    }
}
